package com.centling;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ShowSessionServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		
		HttpSession session = req.getSession(true);
		
		Integer count = (Integer) session.getAttribute("accessacount");		
		String heading;
		if(count == null){
			 heading = "welcome newComer";
			session.setAttribute("accessacount", 0);
		}else{
			 heading = "welcome back";
			session.setAttribute("accessacount", count+1);
		}
		
		PrintWriter writer = resp.getWriter();
		resp.setContentType("text/html");
		
		writer.write("heading: "+heading);
		writer.write("<br/>");
		
		writer.write("jessionid: "+session.getId());
		writer.write("<br/>");
		
		writer.write("is new: "+session.isNew());
		writer.write("<br/>");
		
		writer.write("count: "+session.getAttribute("accessacount"));
		writer.write("<br/>");
	}

	
	
}
